/**
 * Created by Egan on 2015/1/19.
 */
module catgame{

    export class SuccessPanel extends egret.Sprite{

        private tap_textfield:egret.TextField;
        private rank_textfield:egret.TextField;
        private beat_textfield:egret.TextField;
        private title_textfield:egret.TextField;
        private share_btn:egret.Bitmap;
        private repaly_btn:egret.Bitmap;
        private mao2_btn:egret.Bitmap;
        private titles_arr:string[]=["塞外高手","神精病博士","神经大神","你是我的小苹果","院长派来的救兵","精神病院长","扫地僧","传说中的高手","风骚的少年","白天睡觉喵","隔壁王伯伯"];
        private title2_arr:string[]=["神经大条","我是处女座的","停不下来","你是我的小苹果","喵了个咪的","M78星人","凤姐夫","笑而不语"];


        public constructor(){
            super();

            var bg = this.createBitmapByName("victory_bg");//开始按钮
            this.tap_textfield= new egret.TextField();
            this.tap_textfield.width = 400;
            this.tap_textfield.textColor = 0xff0000;
            this.tap_textfield.textAlign = egret.HorizontalAlign.CENTER;
            this.tap_textfield.text = "您用13步抓住了神经猫";
            this.tap_textfield.size = 22;
            this.tap_textfield.x = 20;
            this.tap_textfield.y = 140;

            this.rank_textfield= new egret.TextField();
            this.rank_textfield.width = 400;
            this.rank_textfield.textColor = 0xffffff;
            this.rank_textfield.textAlign = egret.HorizontalAlign.CENTER;
            this.rank_textfield.text = "神经全国排名421位";
            this.rank_textfield.size = 22;
            this.rank_textfield.strokeColor = 0x000000;
            this.rank_textfield.stroke = 2;
            this.rank_textfield.x = 20;
            this.rank_textfield.y = 170;

            this.beat_textfield= new egret.TextField();
            this.beat_textfield.width = 400;
            this.beat_textfield.textColor = 0xff0000;
            this.beat_textfield.textAlign = egret.HorizontalAlign.CENTER;
            this.beat_textfield.size = 22;
            this.beat_textfield.text = "击败了精神病院80%的精神病患者";
            this.beat_textfield.x = 20;
            this.beat_textfield.y = 200;

            this.title_textfield= new egret.TextField();
            this.title_textfield.width = 400;
            this.title_textfield.textColor = 0xff0000;
            this.title_textfield.textAlign = egret.HorizontalAlign.CENTER;
            this.title_textfield.size = 24;
            this.title_textfield.text = "获得称号：思维广";
            this.title_textfield.x = 20;
            this.title_textfield.y = 230;


            this.share_btn = this.createBitmapByName("share_btn");//开始按钮
            this.share_btn.x = 10
            this.share_btn.y = bg.height + 20;
            this.share_btn.touchEnabled = true;//开启触碰
            this.share_btn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.doShare,this);//点击按钮开始游戏

            this.repaly_btn = this.createBitmapByName("replay_btn");//开始按钮
            this.repaly_btn.x = 220
            this.repaly_btn.y = bg.height + 20;
            this.repaly_btn.touchEnabled = true;//开启触碰
            this.repaly_btn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.doRepaly,this);//点击按钮开始游戏

            this.mao2_btn = this.createBitmapByName("mao2");//开始按钮
            this.mao2_btn.x = 90
            this.mao2_btn.y = bg.height - 80;
            this.mao2_btn.touchEnabled = true;//开启触碰
            this.mao2_btn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.doJump,this);//点击按钮开始游戏

            this.addChild(bg);
            this.addChild(this.tap_textfield);
            this.addChild(this.rank_textfield);
            this.addChild(this.beat_textfield);
            this.addChild(this.title_textfield);
            this.addChild(this.share_btn);
            this.addChild(this.repaly_btn);
            this.addChild(this.mao2_btn);
        }

        public doShare(evt:egret.TouchEvent):void{
            this.dispatchEventWith("shareEvent");
        }

        public doRepaly(evt:egret.TouchEvent):void{
            this.dispatchEventWith("replayEvent");
        }

        public doJump(evt:egret.TouchEvent):void{
            console.log("doJump");
        }

        public score(n:number){
            this.tap_textfield.text = "您用"+n+"步抓住了神经猫";
            this.rank_textfield.text = "神经全国排名"+ Math.floor(n*1234678 + Math.random()* n*500) +"位";
            this.beat_textfield.text = "击败了精神病院"+(100-Math.floor(n*Math.random()))+"%的精神病患者";
            var title_str: string;
            if(n < 11){
                title_str = this.titles_arr[n];
            }else{
                title_str = this.title2_arr[Math.floor(Math.random()*this.title2_arr.length)];
            }
            this.title_textfield.text = "获得称号：" +title_str;
        }

        private createBitmapByName(name:string):egret.Bitmap {
            var result:egret.Bitmap = new egret.Bitmap();
            var texture:egret.Texture = RES.getRes(name);
            result.texture = texture;
            return result;
        }

    }

}